package 力扣链表;

public class Leedcode19删除链表的倒数第N个结点 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        int len = 1;
        ListNode node = head;
        int count = 1;
        while(node.next != null){
            len++;
            node = node.next;
        }
        node = head;
        if(len == n){
            head = head.next;
            return head;
        }
        while(count < len-n){
            node = node.next;
            count++;
        }
        node.next = node.next.next;
        return head;
    }
}
